from django.conf import settings
from django.core.mail import send_mail

from celery_tasks.main import app
from meiduo_mall.libs.yuntongxun.sms import CCP


@app.task(bind=True)
def send_verify_url(self, verify_url, email):
    # ccp = CCP()
    # ccp.send_template_sms(mobile, [sms_code, time], 1)
    result = -1
    try:
        result = send_mail(
            subject="美多商城邮箱激活",
            message=verify_url,
            from_email=settings.EMAIL_FROM,
            recipient_list=[email]
        )
    except Exception as e:
        result = -1
    if result == -1:
        print("重试中...")
        self.retry(countdown=5, max_retries=3, exc=Exception("邮件发送失败!!!"))
